﻿/*
 * @file: OccasionBLL.cs
 * @in namespace: BLL
 */

using System;
using DAL;

/// <summary>
/// Summary description for OccasionBLL
/// </summary>
namespace BLL
{
    public class OccasionBLL
    {
        public OccasionBLL()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        #region IOccasion Members

        /// <summary>
        /// GetOccasions
        /// </summary>
        /// <param name="allowFilter">"true" if allow ignore hidden records</param>
        /// <returns>Records corresponding</returns>
        public static Occasion[] GetOccasions(bool allowFilter)
        {
            try
            {
                return DataAccessHelper.GetOccasionDA().GetOccasions(allowFilter);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        /// <summary>
        /// GetOccasionByOccasionID
        /// </summary>
        /// <param name="occasionID">Occasion ID</param>
        /// <param name="allowFilter">"true" if allow ignore hidden records</param>
        /// <returns>Record corresponding</returns>
        public static Occasion GetOccasionByOccasionID(int occasionID, bool allowFilter)
        {
            try
            {
                return DataAccessHelper.GetOccasionDA().GetOccasionByOccasionID(occasionID, allowFilter);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        /// <summary>
        /// InsertOccasion
        /// </summary>
        /// <param name="_occasion">Occasion entity</param>
        /// <param name="autoNumber">Current Occasion ID inserted</param>
        /// <returns>1 if successful, 0 if error occurred</returns>
        public static int InsertOccasion(Occasion _occasion, out int autoNumber)
        {
            try
            {
                if (_occasion.OccasionName == null || _occasion.OccasionName.Length < 0)
                    throw new OnlineFloralDeliveryException(2, "OccasionName is not allow null or empty");
                else if (OccasionDA.OccasionNameExisted(_occasion.OccasionName) > 0)
                    throw new OnlineFloralDeliveryException(1, "OccasionName already exist");

                return DataAccessHelper.GetOccasionDA().InsertOccasion(_occasion,out autoNumber);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        /// <summary>
        /// DisableOccasion
        /// </summary>
        /// <param name="occasionID">Occasion ID</param>
        /// <param name="isEnable">"true" if allow enable Occasion, "false" if allow hidden Occasion</param>
        /// <returns></returns>
        public static int DisableOccasion(int occasionID, bool isEnable)
        {
            try
            {
                return DataAccessHelper.GetOccasionDA().DisableOccasion(occasionID, isEnable);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        /// <summary>
        /// UpdateOccasion
        /// </summary>
        /// <param name="_occasion">Occasion entity</param>
        /// <returns>1 if successful, 0 if error occurred</returns>
        public static int UpdateOccasion(Occasion _occasion)
        {
            try
            {
                if (_occasion.OccasionID == 0)
                    throw new OnlineFloralDeliveryException(2, "OccasionID is not allow null or less than 0");
                else if (_occasion.OccasionName == null || _occasion.OccasionName.Length < 0)
                    throw new OnlineFloralDeliveryException(2, "OccasionName is not allow null or less than 0");
                else if (OccasionDA.OccasionNameExisted(_occasion.OccasionName) > 0)
                    throw new OnlineFloralDeliveryException(1, "OccasionName already exist");

                return DataAccessHelper.GetOccasionDA().UpdateOccasion(_occasion);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        #endregion
    }
}